﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __DC02BCF2_DAEA_4456_B85D_EB0DBE00346C__
#define __DC02BCF2_DAEA_4456_B85D_EB0DBE00346C__

#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{
    // 
    // dynamic_impl
    // 
    class dynamic_impl : public xos_stl::mem_item< release_impl< dynamic_impl >, thread_lock >,
        public i_dynamic
    {
    public:
        typedef release_impl< dynamic_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
        dynamic_impl();
        ~dynamic_impl();

    protected:
        char m_szFullPath[4096];
        char m_szFileName[1024];
        void * m_hModule;

    public:
		int init();
        int term();

    public:
        // 
        // combine load and get_proc_by_name.
        // 
        // 1.try to load : lpszPath/lpszFileName.ext first, if failed, then try : lpszPath/lpszSearchPath/lpszFileName.ext
        // 
        int load_and_get( void ** ppv, const char * lpszPath, const char * lpszFileName, const char * lpszProcName, const char * lpszExt, const char * lpszSearchPath );

        // 
        // use different ext whith different platform. win is dll, linux is so, mac is dylib
        // 
        int load( const char * lpszFullPath, const char * lpszFile, const char * lpszExt );

        // 
        // get proc address by name
        // 
        int get_proc_by_name( void ** ppv, const char * lpszProcName );

        // 
        // get full path and file name
        // 
        const char * get_full_path( char * lpszFullPath, int nBufSize );
        const char * get_file_name( char * lpszFileName, int nBufSize );

        // 
        // free loaded module
        //
        int free();
    };
} // xos

#endif // __DC02BCF2_DAEA_4456_B85D_EB0DBE00346C__
